package com.fan.configserver.service;

import com.fan.configserver.mapper.ResourceItemMapper;
import com.fan.configserver.po.Resource;
import com.fan.configserver.po.ResourceItem;
import com.fan.configserver.po.ResourceItemExample;
import com.fan.configserver.vo.ResourceItemRequest;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * java类简单作用描述
 *
 * @Description: java类作用描述
 * @Author: hf
 * @CreateDate: 2018/9/5 15:46
 * @UpdateUser: hf
 * @UpdateDate: 2018/9/5 15:46
 * @UpdateRemark: The modified content
 * @Version: 1.0
 */
@Transactional
@Service
public class ResourceItemService {
    @Autowired
    ResourceItemMapper resourceItemMapper;


    public void addResourceItem(ResourceItemRequest resourceItemRequest) {
        ResourceItem resourceItem = new ResourceItem();
        BeanUtils.copyProperties(resourceItemRequest, resourceItem);
        resourceItemMapper.insertSelective(resourceItem);
    }


    public void delResourceItem(Long resourceItemId) {
        resourceItemMapper.deleteByPrimaryKey(resourceItemId);
    }


    public void updateResourceItem(ResourceItem resourceItem) {
        resourceItemMapper.updateByPrimaryKeySelective(resourceItem);
    }


    public ResourceItem getResourceItem(Long resourceItem) {
        return resourceItemMapper.selectByPrimaryKey(resourceItem);
    }

    public List<ResourceItem> getResourceByResourceEnvId(Long resourceId, Long resourceEnvId) {
        ResourceItemExample resourceItemExample = new ResourceItemExample();
        ResourceItemExample.Criteria criteria = resourceItemExample.createCriteria();
        criteria.andResourceEnvIdEqualTo(resourceEnvId);
        return resourceItemMapper.selectByExample(resourceItemExample);
    }

}
